import http from '@/api'
import { UserApi } from '@/api/interface/user'
import { ReqPage, UniCloudParams } from '@/api/interface'
import { CaptchaScene } from '@/enums/uniCloud'

/**
 * @name 用户管理模块
 */
// 获取注册验证码
export const registerCaptchaApi = () => {
  return http.post(`/uni-id-co/createCaptcha`, {
    params: { scene: CaptchaScene.Register }
  })
}

// 注册普通用户
export const registerUserApi = (params: UniCloudParams<UserApi.RegisterUser>) => {
  return http.post(`/uni-id-co/registerUser`, params)
}

// 获取用户列表
export const getUserListApi = (params: UniCloudParams<ReqPage>) => {
  return http.post<UserApi.UniCloudUser[]>(`/mo-admin/getUsers`, params)
}

// 管理员添加用户
// https://doc.dcloud.net.cn/uniCloud/uni-id/cloud-object.html#add-user
export const addUserApi = (params: UniCloudParams<UserApi.AddUser>) => {
  return http.post(`/uni-id-co/addUser`, params)
}

// 管理员添加用户
// https://doc.dcloud.net.cn/uniCloud/uni-id/cloud-object.html#add-user
export const checkUserNameApi = (params: UniCloudParams<{ username: string }>) => {
  return http.post(`/mo-admin/checkUserName`, params)
}

// 管理员修改用户
// https://doc.dcloud.net.cn/uniCloud/uni-id/cloud-object.html#update-user
export const updateUserApi = (params: UniCloudParams<UserApi.AddUser>) => {
  return http.post(`/uni-id-co/updateUser`, params)
}

// 管理员删除用户
export const deleteUserApi = (params: UniCloudParams<{ uid: string }>) => {
  return http.post(`/mo-admin/deleteUser`, params)
}
